package com.zhuannimei.view;

import android.content.Context;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.LightingColorFilter;
import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;

public class XXButton extends Button {

	public XXButton(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	public XXButton(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public XXButton(Context context) {
		super(context);
	}

	@Override
	public void setOnClickListener(OnClickListener l) {
		setOnTouchListener(null);
		super.setOnClickListener(l);
	}

	@Override
	public void setOnTouchListener(OnTouchListener l) {
		super.setOnTouchListener(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				switch (event.getAction()) {
				case MotionEvent.ACTION_DOWN: {
					v.getBackground().setColorFilter(
							new LightingColorFilter(-3355444, 1));
					v.getBackground().setAlpha(200);
					v.invalidate();
					break;
				}
				case MotionEvent.ACTION_UP: {
					v.getBackground().clearColorFilter();
					v.getBackground().setAlpha(255);
					v.invalidate();
					break;
				}
				}
				return false;
			}
		});
	}
}
